﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;
using Nova.Parsing;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.Message"/>.
    /// </summary>
    public class MessageVM : AnnotationVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(Message),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new MessageVM((Message)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// The view model for a <see cref="CodeDOM.Message"/>.
        /// </summary>
        public MessageVM(Message message, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(message, dictionary)
        { }

        /// <summary>
        /// The view model for a <see cref="CodeDOM.Message"/>.
        /// </summary>
        public MessageVM(Message message)
            : base(message, null)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.Message"/> model.
        /// </summary>
        public Message Message
        {
            get { return (Message)CodeObject; }
        }

        #endregion

        #region /* RENDERING */

        public override void Render(CodeRenderer renderer, RenderFlags flags)
        {
            if (!flags.HasFlag(RenderFlags.SuppressNewLine))
                renderer.NewLine();
            RenderSeverityImage(renderer, flags);
            renderer.RenderText(Message.Text, NORMAL_BRUSH, TextStyle.Proportional, this);
        }

        public void RenderSeverityImage(CodeRenderer renderer, RenderFlags flags)
        {
            string imageName = null;
            switch (Message.Severity)
            {
                case MessageSeverity.Error:       imageName = "/Images/Error.png"; break;
                case MessageSeverity.Warning:     imageName = "/Images/Warning.png"; break;
                case MessageSeverity.Suggestion:  imageName = "/Images/Info.png"; break;
                case MessageSeverity.Hint:        imageName = "/Images/Info.png"; break;
                case MessageSeverity.Information: imageName = "/Images/Info.png"; break;
            }
            if (imageName != null)
                renderer.RenderImage(imageName, 16, 16, this);
        }

        #endregion
    }

    /// <summary>
    /// The view model for a <see cref="CodeDOM.TokenMessage"/>.
    /// </summary>
    public class TokenMessageVM : MessageVM
    {
        #region /* STATICS */

        internal static new void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(TokenMessage),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new TokenMessageVM((TokenMessage)codeObject, dictionary); });
        }

        #endregion

        #region /* FIELDS */

        protected Token _token;

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// The view model for a <see cref="CodeDOM.TokenMessage"/>.
        /// </summary>
        protected internal TokenMessageVM(TokenMessage tokenMessage, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(tokenMessage, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.TokenMessage"/> model.
        /// </summary>
        public TokenMessage TokenMessage
        {
            get { return (TokenMessage)CodeObject; }
        }

        #endregion
    }
}
